/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.engin.treasury;

import ac.engin.archive.clients;
import ac.settings.dataModel;
import static ac.settings.dataModel.TABLE_clients_data;
import ac.settings.files;
import ac.settings.sqlQuerys;
import ac.uitls.propertiesOperation;
import java.util.Date;

/**
 *
 * @author ismail
 */
public class treasuryOut extends ac.ui.FrameOperationTemplat implements dataModel, files, sqlQuerys {

    String Table = TABLE_treasury_out;
    String actionField = "treasury_id";
    String sqlAll = SQL_treasuryOutAll;

    String sqlFile = SQL_treasuryOut_File;

    String ReportStatus = REPORT_treasury_Out_status;

    ac.engin.treasury.treasuryData t = new ac.engin.treasury.treasuryData();
    clients c = new clients();

    public void reProcess(String tid, String Cid, double am) {
        t.AddToTreasury(tid, am);
        c.addTobalance(Cid, am);

    }

    public void doProcess(String tid, String Cid, double am) {

        t.CutToTreasury(tid, am);
        c.Cutbalance(Cid, am);

    }

    public String getlastID() {
        String[] r;
        r = db.getRow(Table, " max(id) as m ", "");
        return r[0];

    }

    public String[] getRow(String id) {
        String[] r;
        r = db.getRow(Table, "*", "id='" + id + "'");
        return r;

    }

    public double getAmount(String id) {

        double d = 0d;

        String[] oldb_data = getRow(id);

        if (oldb_data[2] != null) {

            d = Double.parseDouble(oldb_data[6]);
        }

        return d;

    }
    propertiesOperation po = new propertiesOperation();

    public String[] returnInstallData(String id) {

        String[] sellDati = db.getRow(TABLE_installment_items, "*", "id=" + id);
        String[] sellData = db.getRow(TABLE_installment, "*", "id=" + sellDati[1]);

        return new String[]{"noValue", sellData[6], sellData[6], "noValue", "noValue", sellDati[5], po.getWord("frame.Installment") + " " + po.getWord("label.number") + sellData[0], "noValue", "noValue"};

    }

    public void reportView(String url, String where, String[] updateTitles) {
        TabelString = Table;
        ac.reportes.reportes.updateReporteTitles(updateTitles[0],
                updateTitles[1],
                updateTitles[2],
                updateTitles[3],
                updateTitles[4]);

        setPrint(url, sqlAll + where);
    }

    public void reportViewForClinte(String Clinte_id, Date d1, Date d2) {
        String[] reptitles = new String[5];

        String where = " where 1=1 ";

        if (Clinte_id != null && !Clinte_id.equals("")) {
            String clinte = db.getRow(TABLE_clients_data, "*", Integer.parseInt(Clinte_id))[1];
            reptitles[1] = po.getWord("label.client_title") + " : " + clinte;

            where += " and " + Table + ".client='" + Clinte_id + "'";

        } else {

            reptitles[1] = "-";

        }
        if (d1 != null && d2 != null) {
            where += " and   " + ac.lib.data.dateTime.updateSerechDates(Table + ".date", d1, d2);
            reptitles[2] = po.getWord("label.from") + " " + d1.toString() + " " + po.getWord("label.to") + " " + d2.toString();
        } else {
            reptitles[2] = "-";
        }
        reptitles[0] = po.getWord("title.retportIntreasurySClinte");
        reptitles[3] = "-";
        reptitles[4] = "-";
        this.reportView(ReportStatus, where, reptitles);
    }

    public void reportViewForAll(String Clinte_id, String T_id, String O_id, Date d1, Date d2) {
        String[] reptitles = new String[5];

        String where = " where 1=1 ";

        if (Clinte_id != null && !Clinte_id.equals("")) {
            String clinte = db.getRow(TABLE_clients_data, "*", Integer.parseInt(Clinte_id))[1];
            reptitles[1] = po.getWord("label.client_title") + " : " + clinte;

            where += " and " + Table + ".client='" + Clinte_id + "'";

        } else {

            reptitles[1] = "-";

        }

        if (O_id != null && !O_id.equals("")) {
            String clinte = db.getRow(tableAddstree, "*", Integer.parseInt(O_id))[1];
            reptitles[4] = po.getWord("label.Official") + " : " + clinte;

            where += " and " + Table + ".Official='" + O_id + "'";

        } else {

            reptitles[4] = "-";

        }

        if (T_id != null && !T_id.equals("")) {
            String clinte = db.getRow(tableAddstree, "*", Integer.parseInt(T_id))[1];
            reptitles[3] = po.getWord("label.treasury") + " : " + clinte;

            where += " and " + Table + ".treasury='" + T_id + "'";

        } else {

            reptitles[3] = "-";

        }

        if (d1 != null && d2 != null) {
            where += " and   " + ac.lib.data.dateTime.updateSerechDates(Table + ".date", d1, d2);
            reptitles[2] = po.getWord("label.from") + " " + d1.toString() + " " + po.getWord("label.to") + " " + d2.toString();
        } else {
            reptitles[2] = "-";
        }
        reptitles[0] = po.getWord("title.retportOuttreasury");

        this.reportView(ReportStatus, where, reptitles);
    }

}
